#!/bin/bash

UT_LOG_FILE=ut_result.xml
UT_EXE_FILE_NAMES="lcd_app_frame_work_unit_test lcdappd_unit_test"

InitUTEnv()
{
	PATH_LIB_LIST=`find ./ -name "lib"`;
	for PATH_LIB in ${PATH_LIB_LIST}
	do
		LD_LIBRARY_PATH=${PATH_LIB}:${LD_LIBRARY_PATH};
	done	
}

RunUT()
{

	for EXE_FILE in ${UT_EXE_FILE_NAMES}
	do
		echo "start to run ${EXE_FILE}"
		chmod u+x ${EXE_FILE};
		./${EXE_FILE} --gtest_output=xml:${UT_LOG_FILE};
		if [ $? -ne 0 ] 
		then
				return $?;
		fi
	done

	return 0;
}

if [ $# -lt 1 ]
then
	echo -e "Useage:$0  ut_log_file_name\nExample:\n\t$0 /root/ut_result_log.xml\n";
#	exit 1;
	UT_LOG_FILE="ut_result_log.xml"
else
	UT_LOG_FILE=$1;
fi
rm -f ${UT_LOG_FILE};
InitUTEnv;
RunUT;
exit $?;

